﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TpBaseObjects.Base;
using Tp.Base;

namespace Tp.GUI.Dialog {
    public partial class CalcMenu : Form {

        #region Members

        private TpMenu myLocalMenu;
        private byte listLevel = 0;
        private byte buttonLevel = 0;
        
        #endregion

        public CalcMenu() {
            InitializeComponent();
        }

        public CalcMenu(TpMenu myMenu) :this(){
            this.myLocalMenu = myMenu;
            this.Cancel = true;
            this.SelectedColumn = 0;
        } 

        private void CalcMenu_Load(object sender, EventArgs e) {
            foreach (TpMenuGroup group in myLocalMenu.MyGroups) {
                listLevel += 1;
                if (listLevel <= 4) {
                    buttonLevel = 0;
                    //Setze Panel
                    Panel panel = (Panel)this.Controls["panel" + listLevel.ToString()];
                    //Setze Label
                    Label lbl = (Label)this.Controls["label" + listLevel.ToString() + "00"];
                    lbl.Text = group.GroupName;

                    foreach (TpMenuGroupItem groupItem in group.MyItems) {
                        buttonLevel += 1;
                        if (buttonLevel <= 10) {
                            Button btn = (Button)panel.Controls["button" + listLevel.ToString() + String.Format("{0:00}", buttonLevel)];
                            btn.Text = groupItem.MenuName;
                            btn.Tag = groupItem.ColNo.ToString();
                            btn.Visible = true;
                            btn.Click += ButtonOnClick;
                        }
                    }
                }
            }
        }

        private void ButtonOnClick(object sender, EventArgs e) {
            Button btn = sender as Button;
            this.Cancel = false;
            this.SelectedColumn = Convert.ToInt32(btn.Tag);
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e) {
            this.Cancel = true;
            this.Close();
        }

        public bool Cancel {
            get;
            set;
        }

        public int SelectedColumn {
            get;
            set;
        }
    }
}
